// JavaScript Document
 //定制轮播
   (function(){
        var act,le;
        //switchable 初始化。
        jq('.switchable-content li').css('display','none');
        jq('.switchable-triggerBox li').eq(0).addClass('active');
        jq('.switchable-content li').eq(0).css({'z-index':'1','display':'block'});
        jq('.switchable-content li').eq(0).addClass('slide_index');
         var triggerBox_len = jq('.switchable-content .switchable-panel').length,
            triggerBox_width = (1002/triggerBox_len)-2;
        jq('.js-tri li').width(triggerBox_width);
        //轮播预知。
        jq('.switchable-triggerBox li').hover(function(){
            var index = jq(this).index(),
                img = jq(this).parents('.ad-slide-full').find('.switchable-content .switchable-panel').eq(index).find('.pic').css('background-image'),
                img_le = img.length,
                img_str = img.substr(4,img_le - 5);
            jq(this).append('<div class="predict-pic"><img src='+img_str+' /><a href="javascript:void(0)"></a></div>');
            click_event();
        },function(){
             jq(this).find('.predict-pic').remove();
             jq('.switchable-triggerBox li').unbind('click');
        });
        //轮播定时器
        function slide(){
                act = jq('.switchable-content li.active').index();
                le = jq('.ex-slide1 .switchable-content li').length;
            if (act < le-1 ) {
                jq('.switchable-content .active').removeClass('active').fadeOut(1000).css('z-index','10');
                jq('.switchable-content li').eq( act+1 ).addClass('active').css({'z-index':'1','display':'block'});
                jq('.switchable-triggerBox li').eq( act+1 ).addClass('active').siblings().removeClass('active');
                jq('.switchable-triggerBox li').eq( act+1 ).find('.zs').animate({width:triggerBox_width},5000,function(){
                    jq('.switchable-triggerBox li').find('.zs').css('width','0px');
                });
            }else{
                jq('.switchable-content .active').removeClass('active').fadeOut(1000).css('z-index','10');
                jq('.switchable-content li').eq(0).addClass('active').css({'z-index':'1','display':'block'});
                jq('.switchable-triggerBox li').eq(0).addClass('active').siblings().removeClass('active');
                jq('.switchable-triggerBox li').eq( 0 ).find('.zs').animate({width:triggerBox_width},5000,function(){
                    jq('.switchable-triggerBox li').eq( 0 ).find('.zs').css('width','0px');
                });
            };
        };
        var time = setInterval(slide,5000);
        //轮播DOM
        jq('.slide-next').click(function(){
                act = jq('.switchable-content li.active').index();
                le = jq('.ex-slide1 .switchable-content li').length;
            if (act < le - 1) {
                jq('.switchable-content .active').removeClass('active').fadeOut(1000).css('z-index','10');
                jq('.switchable-content li').eq( act+1 ).addClass('active').css({'z-index':'1','display':'block'});
                jq('.switchable-triggerBox li').eq( act+1 ).addClass('active').siblings().removeClass('active');
                jq('.switchable-triggerBox li').find('.zs').stop(true,true);
                clearInterval(time);
                time = setInterval(slide,5000);
                jq('.switchable-triggerBox li').eq( act+1 ).find('.zs').animate({width:triggerBox_width},5000,function(){
                    jq('.switchable-triggerBox li').find('.zs').css('width','0px');
                });
            }else{
                jq('.switchable-content .active').removeClass('active').fadeOut(1000).css('z-index','10');
                jq('.switchable-content li').eq( 0 ).addClass('active').css({'z-index':'1','display':'block'});
                jq('.switchable-triggerBox li').eq( 0 ).addClass('active').siblings().removeClass('active');
                jq('.switchable-triggerBox li').find('.zs').stop(true,true);
                clearInterval(time);
                time = setInterval(slide,5000);
                jq('.switchable-triggerBox li').eq( 0 ).find('.zs').animate({width:triggerBox_width},5000,function(){
                    jq('.switchable-triggerBox li').find('.zs').css('width','0px');
                    slide();
                });
            };  
        });
        jq('.slide-last').click(function(){
                act = jq('.switchable-content li.active').index();
                le = jq('.ex-slide1 .switchable-content li').length;
            if (act != 0) {
                jq('.switchable-content .active').removeClass('active').fadeOut(1000).css('z-index','10');
                jq('.switchable-content li').eq( act-1 ).addClass('active').css({'z-index':'1','display':'block'});
                jq('.switchable-triggerBox li').eq( act-1 ).addClass('active').siblings().removeClass('active');
                jq('.switchable-triggerBox li').find('.zs').stop(true,true);
                clearInterval(time);
                time = setInterval(slide,5000);
                jq('.switchable-triggerBox li').eq( act-1 ).find('.zs').animate({width:triggerBox_width},5000,function(){
                    jq('.switchable-triggerBox li').find('.zs').css('width','0px');
                });
            }else{
                jq('.switchable-content .active').removeClass('active').fadeOut(1000).css('z-index','10');
                jq('.switchable-content li').eq(le-1).addClass('active').css({'z-index':'1','display':'block'});
                jq('.switchable-triggerBox li').eq(le-1).addClass('active').siblings().removeClass('active');
                jq('.switchable-triggerBox li').find('.zs').stop(true,true);
                clearInterval(time);
                time = setInterval(slide,5000);
                jq('.switchable-triggerBox li').eq( act-1 ).find('.zs').animate({width:triggerBox_width},5000,function(){
                    jq('.switchable-triggerBox li').find('.zs').css('width','0px');
                });
            };  
        });
        slide();
        //轮播stop
        jq('.ex-slide1').hover(function(){
            jq(this).find('.slide-last').fadeIn();
            jq(this).find('.slide-next').fadeIn();
            // clearInterval(time);
        },function(){
            jq(this).find('.slide-last').fadeOut();
            jq(this).find('.slide-next').fadeOut();
            // time = setInterval(slide,5000);
        });
        function click_event(){
            jq('.switchable-triggerBox li').on('click',function(){
                act = jq(this).index();
                jq('.switchable-content .active').removeClass('active').fadeOut(1000).css('z-index','10');
                jq('.switchable-content li').eq( act ).addClass('active').css({'z-index':'1','display':'block'});
                jq(this).addClass('active').siblings().removeClass('active');
                jq('.switchable-triggerBox li').unbind('click');
                jq('.switchable-triggerBox li').find('.zs').stop(true,true);
                clearInterval(time);
                time = setInterval(slide,5000);
                jq('.switchable-triggerBox li').eq( act ).find('.zs').animate({width:triggerBox_width},5000,function(){
                    jq('.switchable-triggerBox li').find('.zs').css('width','0px');
                });
            });
        }
   })();